/*
 * @Author: zjf
 * @Date: 2023-12-06 16:07:24
 * @LastEditors: zjf
 * @LastEditTime: 2023-12-07 14:43:39
 * @Description:
 */
import wkt from "wellknown";
function convertGeometryToWK(geojson) {
    return wkt.stringify(geojson);
}
function convertFeatureToWK(geojson) {
    return convertGeometryToWK(geojson.geometry);
}
function convertFeatureCollection(featureCollection) {
    if (featureCollection.type !== "FeatureCollection") {
        throw new Error("GeoJSON is not a FeatureCollection");
    }
    return `GEOMETRYCOLLECTION(${featureCollection.features.map((d) => convertFeatureToWK(d)).join(",")})`;
}
function convertToWK(geojson) {
    switch (geojson.type) {
        case "Feature":
            return convertFeatureToWK(geojson);
        case "FeatureCollection":
            return convertFeatureCollection(geojson);
        default:
            return convertGeometryToWK(geojson);
    }
}
function parseFromWK(item) {
    var parsed = wkt.parse(item) || {}
    if (parsed.type == "GeometryCollection") {
        const features = parsed.geometries.map(t => ({ 'type': 'Feature', 'geometry': t }))
        return {
            type: "FeatureCollection",
            features: features || [],
        };
    }
    return parsed;
}
export {
    convertFeatureCollection,
    convertFeatureToWK,
    convertGeometryToWK,
    convertToWK,
    parseFromWK
};
